package org.stjs.generator.writer;

import java.util.ArrayList;
import java.util.List;

import org.stjs.generator.GenerationContext;
import org.stjs.generator.javascript.JavaScriptBuilder;

import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.tree.Tree;

public class CompilationUnitWriter<JS> implements
		WriterContributor<CompilationUnitTree, JS> {

	@SuppressWarnings("unchecked")
	@Override
	public JS visit(WriterVisitor<JS> visitor, CompilationUnitTree tree,
			GenerationContext<JS> context) {
		List<JS> children = new ArrayList<JS>();
		for (Tree type : tree.getTypeDecls()) {
			children.add(visitor.scan(type, context));
		}
		JavaScriptBuilder<JS> js = context.js();
		// return
		// js.root(Collections.singleton(js.functionCall(
		// js.name("define"),
		// Arrays.asList(js.array(Arrays.asList(js.string("$"),
		// js.string("angular"))), js.function(null,
		// Arrays.asList(js.name("$"), js.name("angular")),
		// js.block(children))))));
		return context.js().root(children);
	}
}
